package com.nuanshui.heatedloan.credit.convert;

import com.nuanshui.heatedloan.credit.constant.CreditConverterType;
import com.nuanshui.heatedloan.middleware.convert.Converter;
import com.nuanshui.framework.lang.DateUtil;
import com.nuanshui.heatedloan.credit.constant.BorrowType;
import com.nuanshui.heatedloan.credit.constant.HomePageConstant;
import com.nuanshui.heatedloan.credit.constant.OrderType;
import com.nuanshui.heatedloan.credit.facade.PayOrderInfoService;
import com.nuanshui.heatedloan.credit.vo.PayOrderInfoVO;
import com.nuanshui.heatedloan.middleware.convert.annotation.ConverterAttribute;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@ConverterAttribute(typeId = CreditConverterType.LightOrderStatusToContent)
public class LightOrderStatusToContentConverter implements Converter {

    @Autowired
    private PayOrderInfoService payOrderInfoService;

    @Override
    public String convert(Object s, Object param) {

        String content=null;

        String userId=s.toString();

        List<PayOrderInfoVO> payOrderInfoVOList = payOrderInfoService.loadPayOrderInfoVOByUserIdAndBorrowType(userId, BorrowType.LIGHTLOAN);
        if (payOrderInfoVOList != null && payOrderInfoVOList.size() == 1) {
            PayOrderInfoVO payOrderInfoVO = payOrderInfoVOList.get(0);
            if (payOrderInfoVO != null) {
                switch (payOrderInfoVO.getOrderStatus()) {
                    case OrderType.REVIEWORDER:
                        content=HomePageConstant.ORDER_REVIEWING;
                        break;
                    case OrderType.LENDINGORDER:
                    case OrderType.APPROVEDORDER:
                        content=HomePageConstant.ORDER_LENDING;
                        break;
                    case OrderType.OVERDUEPAYMENT:
                        content="您已逾期" + payOrderInfoVO.getOverdueDays() + "天";
                        break;
                    case OrderType.NOREIMBURSEMENT:
                        content=DateUtil.format(payOrderInfoVO.getShouldReturnTime(), DateUtil.DEFAULT_DATE_PATTERN) + "为还款日";
                        break;
                    case OrderType.REPAYING:
                        content=HomePageConstant.ORDER_REPAYING;
                        break;
                    default:
                        break;
                }
            }
        }

        return content;
    }
}
